package cn.stylefeng.guns.modular.gridsystem.temperature.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.context.login.LoginContext;
import cn.stylefeng.guns.core.context.login.LoginContextHolder;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ErrorResponseData;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.gridsystem.model.param.BizDeviceParam;
import cn.stylefeng.guns.modular.gridsystem.temperature.model.param.BizTemperatureChannelParam;
import cn.stylefeng.guns.modular.gridsystem.temperature.model.param.BizTemperatureExceptionParam;
import cn.stylefeng.guns.modular.gridsystem.temperature.model.param.BizTemperatureRecordParam;
import cn.stylefeng.guns.modular.gridsystem.temperature.service.BizTemperatureExceptionService;
import org.bouncycastle.asn1.cms.PasswordRecipientInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 开关柜温度 温度预警
 *
 * @author
 * @date 2024-06-05
 */
@RestController
public class BizTemperatureExceptionController {


    @Autowired
    private BizTemperatureExceptionService bizTemperatureExceptionService;


    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @GetMapping("/temperature/error/page")
    @BusinessLog(title = "开关柜温度预警_分页查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(BizTemperatureExceptionParam param) {
        if (ObjectUtil.isEmpty(param.getStationId())) {
            param.setStationId(0);
        }
        return new SuccessResponseData(bizTemperatureExceptionService.pageList(param));
    }


    @PostMapping("/temperature/error/changeStatus")
    @BusinessLog(title = "温度故障_处理状态修改", opType = LogAnnotionOpTypeEnum.UPDATE)
    public ResponseData changeStatus(@RequestBody @Validated({BizTemperatureExceptionParam.change.class}) BizTemperatureExceptionParam param) {
        bizTemperatureExceptionService.changeStatus(param);
        return new SuccessResponseData();
    }


    @GetMapping("/temperature/error/del")
    @BusinessLog(title = "温度故障删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData del(BizTemperatureExceptionParam param) {
        //获取用户信息
        final LoginContext me = LoginContextHolder.me();
        //校验用户角色，管理员才能删除
        if (!me.isSuperAdmin()) {
            return new ErrorResponseData(403, "无权操作");
        }
        if (ObjectUtil.isEmpty(param.getId())) {
            return ResponseData.error("参数不能为空！");
        }
        bizTemperatureExceptionService.del(param);
        return new SuccessResponseData();
    }


}
